package com.fuxue.mapper;

import com.fuxue.dto.UserDTO;
import com.fuxue.dto.UserUpAdvateDTO;
import com.fuxue.dto.UserUpNameDTO;
import com.fuxue.entity.AllFiled;
import com.fuxue.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface UserMapper {

@Select("select * from user where user_name=#{userName}")
   User getByUsername(String username);

@Insert("insert into user (hao,name, password, user_name, phone, college,creatime) values " +
        "(#{hao},#{name},#{password},#{userName},#{phone},#{college},#{creatTime})")
   void insert(UserDTO userDTO);

@Select("select user_id from user where hao = #{hao}")
   Integer getIdByHao(String hao);

@Select("select * from user where user_id = #{id}")
   User getById(Integer id);

@Update("update user set user_name = #{userName} where user_id = #{userId}")
   void updateNameById(UserUpNameDTO userUpNameDTO);

@Update("UPDATE question set user_name = #{userName} where user_id = #{userId}")
   void updateQuestionName(UserUpNameDTO userUpNameDTO);

@Select("select * from user where user_id = #{id}")
   User getUserById(Integer id);

@Update("UPDATE user SET password = #{newpassword} WHERE user_id = #{id}")
   void UpdateNewPassword(Integer id, String newpassword);

@Update("UPDATE user set avatar = #{avatar} where user_id = #{userId}")
   void updateAdvatar(UserUpAdvateDTO userUpAdvateDTO);

@Select("select * from allfiled")
   List<AllFiled> selectAllFiled();
}
